Docker : Use Dockerfile
2016/06/30 |
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management. |
|||||||||||||||||||||||||||||
[1] | The format of Dockerfile is [INSTRUCTION arguments] . Refer to the following description for INSTRUCTION.
|
[2] | For example, Create a Dockerfile to install httpd and add index.html, and also start httpd with 80 port. |
[root@dlp ~]#
vi Dockerfile # create new FROM fedora MAINTAINER serverworld <admin@srv.world> RUN dnf -y install httpd RUN echo "Hello DockerFile" > /var/www/html/index.html EXPOSE 80 CMD ["-D", "FOREGROUND"] ENTRYPOINT ["/usr/sbin/httpd"] # build image ⇒ docker build -t [image name]:[tag] . [root@dlp ~]# docker build -t serverworld/httpd:v1.0 . Sending build context to Docker daemon 11.26 kB Step 1 : FROM fedora ---> f9873d530588 Step 2 : MAINTAINER serverworld <admin@srv.world> ---> Running in 5f39adeb5f98 ---> c2ac72fc0fc1 ..... ..... Removing intermediate container 3fa8b8079a88 Successfully built 86a11f268773[root@dlp ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE serverworld/httpd v1.0 86a11f268773 16 seconds ago 338.3 MB images/fedora_httpd latest 33906951c2a6 About an hour ago 544.9 MB docker.io/fedora latest f9873d530588 9 days ago 204.4 MB # run Container on background [root@dlp ~]# docker run -d -p 80:80 serverworld/httpd:v1.0 437c2504ca443659e535253682cd1055d9f79431fef41d4b22a19058eae69802 docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 437c2504ca44 serverworld/httpd:v1.0 "/usr/sbin/httpd -D F" 26 seconds ago Up 23 seconds 0.0.0.0:80->80/tcp angry_darwin[root@dlp ~]# curl http://localhost/ Hello DockerFile |